//
//  Team9ExpertIdeabookCollectionVC.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/21.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9ExpertIdeabookCollectionVC.h"
#import "Team9ExpertIdeabookCell.h"
#import "Team9JQHeader.h"
#import "Team9DesignVC.h"

@interface Team9ExpertIdeabookCollectionVC ()<UICollectionViewDataSource, UICollectionViewDelegate>



@end

@implementation Team9ExpertIdeabookCollectionVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    // Do any additional setup after loading the view.
    [self createView];
    [self createData];
}
static NSString *reuse = @"ExpertIdeabookCellReuse";
- (void)createView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(WIDTH / 2 - 15, WIDTH / 2 - 15);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 10;
    self.collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:layout];
    self.collectionView.contentInset = UIEdgeInsetsMake(0, 10, 10 + 64, 10);
//    self.collectionView.bounces = NO;
    [self.view addSubview:self.collectionView];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.scrollEnabled = YES;
#warning color!
    self.collectionView.backgroundColor = [UIColor whiteColor];
    
    [self.collectionView registerClass:[Team9ExpertIdeabookCell class] forCellWithReuseIdentifier:reuse];
    self.empty = [Team9EmptyTool toolWithScrollView:self.collectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.array.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    Team9ExpertIdeabookCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuse forIndexPath:indexPath];
    
    cell.model = self.array[indexPath.row];
    return cell;
}
- (void)setArray:(NSArray *)array
{
    if (_array != array) {
        _array = array;
        [self.collectionView reloadData];
    }
}
- (void)createData{
//    [JQAFNetworkTool getUrl:_url success:^(id result) {
//        self.array = [Team9ExpertIdeabookModel baseModelByArr:result[@"data"][@"user_home_liking_collections"][@"collections"]];
//    }];
    self.tool = [Team9RefreshTool toolWithScrollView:self.collectionView url:self.url style:^NSArray *(id result) {
        return [Team9ExpertIdeabookModel baseModelByArr:result[@"data"][@"user_home_liking_collections"][@"collections"]];
    } refresh:^(NSArray *array) {
        self.array = array;
    } empty:self.empty];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    Team9ExpertIdeabookModel *model = self.array[indexPath.row];
    Team9DesignVC *vc = [Team9DesignVC new];
    vc.url = [NSString stringWithFormat:@"http://api.meilijia.com/app/collection_page2?col_id=%@&tab=photo", model.col_id];
    //            NSLog(@"%@", model.modelId);
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
